﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SchemaMonitor.json
{
    public class CPaging : CDict
    {
        //Data
        public readonly string NextUrl;
        public readonly string PrevUrl;
        public CCursors Cursors;

        //Constructors
        public CPaging(Dictionary<string, object> dict) : base(dict)
        {
            NextUrl = AsStr("next");
            PrevUrl = AsStr("previous");
            Cursors = AsCursors("cursors");
        }

        //Derived
        public bool HasNext { get { return !string.IsNullOrEmpty(NextUrl); } }
        public bool HasPrev { get { return !string.IsNullOrEmpty(PrevUrl); } }
        public bool HasBefore { get { return !string.IsNullOrEmpty(Cursors?.Before); } }
        public bool HasAfter { get { return !string.IsNullOrEmpty(Cursors?.Before); } }
        public bool HasCursors { get { return HasBefore || HasAfter; } }
        public string Summary
        {
            get
            {
                var sb = new StringBuilder();
                if (HasNext)
                    sb.Append(" next");
                if (HasPrev)
                    sb.Append("/prev");
                if (HasCursors)
                    sb.Append(Cursors.Summary);
                return sb.ToString();
            }
        }
    }
}
